package mmc.server.shell.ops.function;

import java.util.Vector;

import mmc.server.shell.Shell;
import mmc.server.shell.ShellException;
import mmc.server.shell.ops.Function;
import mmc.server.shell.ops.Operation;

public class For extends Function {

    public For(String text) throws ShellException {
        super(text, "for", 3, true, ";");
    }

    @Override
    public double execute() {
    	throw new RuntimeException(this+" has no double output!");
    }
    
    @Override
    public Object executeComplex(){
    	Vector<Operation> args = arguments.getArguments();
        
        args.get(0).executeDefault();
        
        while(args.get(1).execute()!=0){
	        for(int i=2;i<args.size();i++){
	        	args.get(i).executeDefault();
	        }
	        Shell.checkTime();
        }
        
    	return null;
    }
    
    @Override
    public Class<?> getOutputType(){
    	return void.class;
    }
    
    public static String getDescription(){
    	return formatHelpString("for(init;cond;cmds)","for-loop");
    }
}
